package net.randomice.emf.observables.demo.extlibrary.items.observables;

import java.util.Date;
import net.randomice.emf.observables.demo.extlibrary.items.Item;
import net.randomice.emf.observables.demo.extlibrary.items.ItemsPackage;
import net.randomice.emf.observables.runtime.IObservableAbstractListObject;
import net.randomice.emf.observables.runtime.IObservableObject;
import org.eclipse.core.databinding.observable.Observables;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * An Observable object wrapper for {@link Item}
 * @generated
 */
public class ItemOO implements IObservableObject<Item> {
	// root object stuff

	public final static AbstractCreator<Item, ItemOO> CREATOR = new AbstractCreator<Item, ItemOO>() {
		public ItemOO createRoot(Item object) {
			return new ItemOO(Observables.constantObservableValue(object,
					Item.class));
		}
	};

	public static ItemOO createRoot(Item object) {
		return CREATOR.createRoot(object);
	}

	// instance stuff	

	public final IObservableValue o;
	public final IObservableValue getObservable() {
		return o;
	}

	public ItemOO(IObservableValue observableValue) {
		Object type = observableValue.getValueType();
		if (type instanceof EReference) {
			type = ((EReference) type).getEType().getInstanceClass();
		}
		Assert.isTrue(null == type || Item.class.equals(type));
		o = observableValue;
	}

	public Item getValue() {
		return (Item) o.getValue();
	}

	public void setValue(Item newValue) {
		o.setValue(newValue);
	}

	// generic feature getters

	public IObservableValue getValueFeature(EStructuralFeature feature) {
		if (ItemsPackage.Literals.ITEM__PUBLICATION_DATE.equals(feature)) {
			return getPublicationDate();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableList getListFeature(EStructuralFeature feature) {
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableObject<?> getValueObject(EReference feature) {
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableAbstractListObject<?> getListObject(EReference feature) {
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	// features from type Item

	private IObservableValue publicationDate = null;
	public IObservableValue getPublicationDate() {
		if (null == publicationDate) {
			publicationDate = EMFObservables.observeDetailValue(o.getRealm(),
					o, ItemsPackage.Literals.ITEM__PUBLICATION_DATE);
		}
		return publicationDate;
	}

	public void setPublicationDate(Date value) {
		getPublicationDate().setValue(value);
	}

}
